package com.burstly.lib.component.networkcomponent.burstly.html.ormma;

import android.content.Context;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.webkit.JavascriptInterface;
import com.burstly.lib.component.networkcomponent.burstly.html.ormma.util.OrmmaNetworkBroadcastReceiver;
import com.burstly.lib.util.LoggerExt;

public class OrmmaNetworkController extends OrmmaController
{
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private static final String TAG = "OrmmaNetworkController";
  private OrmmaNetworkBroadcastReceiver mBroadCastReceiver;
  private ConnectivityManager mConnectivityManager;
  private IntentFilter mFilter;
  private int mNetworkListenerCount;

  public OrmmaNetworkController(OrmmaView paramOrmmaView, Context paramContext)
  {
    super(paramOrmmaView, paramContext);
    this.mConnectivityManager = ((ConnectivityManager)paramContext.getSystemService("connectivity"));
  }

  @JavascriptInterface
  public String getNetwork()
  {
    NetworkInfo localNetworkInfo = this.mConnectivityManager.getActiveNetworkInfo();
    String str = "unknown";
    if (localNetworkInfo == null)
      str = "offline";
    while (true)
    {
      LOG.logDebug("OrmmaNetworkController", "getNetwork: {0}", new Object[] { str });
      return str;
      int i;
      switch (1.$SwitchMap$android$net$NetworkInfo$State[localNetworkInfo.getState().ordinal()])
      {
      default:
        i = localNetworkInfo.getType();
        if (i == 0)
          str = "cell";
        break;
      case 1:
        str = "unknown";
        break;
      case 2:
        str = "offline";
        continue;
        if (i == 1)
          str = "wifi";
        break;
      }
    }
  }

  public void onConnectionChanged()
  {
    String str = "window.ormmaview.fireChangeEvent({ network: '" + getNetwork() + "'});";
    LOG.logDebug("OrmmaNetworkController", str, new Object[0]);
    this.mOrmmaView.injectJavaScript(str);
  }

  public void startNetworkListener()
  {
    if (this.mNetworkListenerCount == 0)
    {
      this.mBroadCastReceiver = new OrmmaNetworkBroadcastReceiver(this);
      this.mFilter = new IntentFilter();
      this.mFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
    }
    this.mNetworkListenerCount = (1 + this.mNetworkListenerCount);
    this.mContext.registerReceiver(this.mBroadCastReceiver, this.mFilter);
  }

  public void stopAllListeners()
  {
    if (this.mBroadCastReceiver != null)
      this.mNetworkListenerCount = 0;
    try
    {
      this.mContext.unregisterReceiver(this.mBroadCastReceiver);
      return;
    }
    catch (Exception localException)
    {
      LOG.logThrowable("OrmmaNetworkController", localException);
    }
  }

  public void stopNetworkListener()
  {
    this.mNetworkListenerCount = (-1 + this.mNetworkListenerCount);
    if (this.mNetworkListenerCount == 0)
    {
      this.mContext.unregisterReceiver(this.mBroadCastReceiver);
      this.mBroadCastReceiver = null;
      this.mFilter = null;
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.html.ormma.OrmmaNetworkController
 * JD-Core Version:    0.6.2
 */